package com.cande.loki.exercise.manythread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @auther ROCK CODER
 * @DATE 2022/4/4 9:01
 * @Description 创建线程的几种方法 以及线程中的方法
 */
public class CreateThreadMethod {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//第一种 继承Thread
//第二种 实现runnable
         new Thread(() -> {
            System.out.println("this is a runnable thread");
        }).start();
//第三种 实现Callable
        Callable<Integer> tc = new TestCalable();
        FutureTask ft = new FutureTask(tc);
        Thread aa =  new Thread(ft);
        aa.start();
//        aa.sleep(1000);
//        aa.join();
//        aa.yield();
        System.out.println("this is main thread");
        System.out.println(ft.get());

//第四种 线程池 见线程池那个包
    }
}

class TestCalable implements Callable<Integer>{
    int a = 0;
    @Override
    public Integer call() throws Exception {
        System.out.println(this);
        return a++;
    }
}
